﻿package com.sgcc.nfc.lock.data.local.mapper

import com.sgcc.nfc.lock.data.local.entity.RoomEntity
import com.sgcc.nfc.lock.domain.model.Room
import com.sgcc.nfc.lock.domain.model.RoomStatus

fun RoomEntity.toDomain(): Room = Room(
    roomId = roomId,
    roomName = roomName,
    regionId = regionId,
    regionName = regionName,
    address = address,
    longitude = longitude,
    latitude = latitude,
    status = when (status) {
        0 -> RoomStatus.NORMAL
        1 -> RoomStatus.IN_USE
        2 -> RoomStatus.ALERT
        else -> RoomStatus.UNKNOWN
    },
    lockCount = lockCount,
    openLockCount = openLockCount,
    malfunctionLockCount = malfunctionLockCount,
    locks = emptyList()
)

fun Room.toEntity(): RoomEntity = RoomEntity(
    roomId = roomId,
    roomName = roomName,
    regionId = regionId,
    regionName = regionName,
    address = address,
    longitude = longitude,
    latitude = latitude,
    status = when (status) {
        RoomStatus.NORMAL -> 0
        RoomStatus.IN_USE -> 1
        RoomStatus.ALERT -> 2
        RoomStatus.UNKNOWN -> -1
    },
    lockCount = lockCount,
    openLockCount = openLockCount,
    malfunctionLockCount = malfunctionLockCount
)
